#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void nextPermutation(vector<int> &num) {
	// Start typing your C/C++ solution below
	// DO NOT write int main() function
	if(num.size()<2){
		return;
	}

	// for a num (not the least), find the one close greater than it
	int theindex = 0;
	bool find = false;
	int i;
	for(i=num.size()-2; i>=0; --i){
		for(int j=i+1; j<num.size(); ++j){
			if(num[j] > num[i]){
				if(!find){
					theindex = j;
					find = true;
				}
				else if(num[j] < num[theindex]){
					theindex = j;
				}
			}
		}
		if(find){
			break;
		}
	}
	if(!find){
		// reorder
		sort(num.begin(), num.end());
	}
	else{
		// replace num[i] and num[theindex]
		int temp = num[i];
		num[i] = num[theindex];
		num[theindex] = temp;
		// reorder lower
		sort(num.begin()+i+1, num.end());
	}
}

int main(){
	vector<int> num;
	num.push_back(2);
	num.push_back(3);
	num.push_back(1);
	nextPermutation(num);

	return 0;
}